#pragma once

#include "CallOperationAction.h"

#include "InputPin.h"
#include "Operation.h"
#include "Parameter.h"

namespace uml {

CallOperationAction::CallOperationAction(const QString& umlType)
    : CallAction(umlType) {}

void CallOperationAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    CallAction::fromJson(json, errorList);
    operation_ = JsonSerializable::create<Operation>(json.value("operation"), errorList);

    target_ = JsonSerializable::create<InputPin>(json.value("target"), errorList);

}

void CallOperationAction::toJson(QJsonObject& json) {
    CallAction::toJson(json);
    if (operation_) {
        QJsonObject operation_json;
        operation_->toJson(operation_json);
        json.insert("operation", operation_json);
    }
    if (target_) {
        QJsonObject target_json;
        target_->toJson(target_json);
        json.insert("target", target_json);
    }
}

/// <summary>
/// outputParameters
    /// Return the inout, out and return ownedParameters of the Operation being called.
/// </summary>
    /// <code>
    /// result = (operation.outputParameters())
    /// </code>
shared_ptr<vector<Parameter>> CallOperationAction::outputParameters() const
{
    return nullptr;
}

/// <summary>
/// inputParameters
    /// Return the in and inout ownedParameters of the Operation being called.
/// </summary>
    /// <code>
    /// result = (operation.inputParameters())
    /// </code>
shared_ptr<vector<Parameter>> CallOperationAction::inputParameters() const
{
    return nullptr;
}

/// <summary>
/// operation getter
/// The Operation being invoked.
/// </summary>
shared_ptr<Operation> CallOperationAction::operation() const {
    return operation_;
}

/// <summary>
/// operation setter
/// The Operation being invoked.
/// </summary>
void CallOperationAction::setOperation(shared_ptr<Operation> value) {
    operation_ = value;
}

/// <summary>
/// target getter
/// The InputPin that provides the target object to which the Operation call request
/// is sent.
/// </summary>
shared_ptr<InputPin> CallOperationAction::target() const {
    return target_;
}

/// <summary>
/// target setter
/// The InputPin that provides the target object to which the Operation call request
/// is sent.
/// </summary>
void CallOperationAction::setTarget(shared_ptr<InputPin> value) {
    target_ = value;
}

} // namespace uml
